package com.cicc.its.redisson.lock;

import cn.hutool.json.JSONUtil;
import com.cicc.its.redisson.BaseTest;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.redisson.api.RLock;

import java.util.concurrent.TimeUnit;

/**
 * @author daizh
 * @version v1.0
 * @date 2024/5/19 17:34
 **/
@Slf4j
public class ItsLock extends BaseTest {

    @Test
    public void lock() {
        RLock lock = redisson.getLock("its:cmn:lock");
        lock.lock();
        try {
            log.info("锁信息：" + JSONUtil.toJsonStr(lock));
            TimeUnit.SECONDS.sleep(50);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }
}
